import { deferPromise } from '@/utils/common'
export class MyBox {
  constructor(options) {
    this.options = options
    this.context = options.context
    this.a = 0
    this.b = 0
    //不要再这里进行任何的数据异步操作，统一在绑定后进行操作
    // setInterval(() => {
    //   this.context.$nextTick((res) => {
    //     this.a++
    //     console.log(this.a)
    //   })
    // }, 1e3)
  }
  showDialog() {
    let row = this.context.$refs['c-row']
    console.log(row)
    console.log(`helloworld`)
    this.a++
  }
  init2() {
    this.c++
  }
  async init() {
    console.time('start1')
    this.a = await this.getData()
    this.b = await this.getData2()
    console.timeEnd('start1')

    console.time('start2')
    this.getData().then((res) => {
      this.a = res
      console.log(res)
    })
    this.getData2().then((res) => {
      this.b = res
      console.log(res)
    })
    console.timeEnd('start2')
  }
  getData() {
    this.a = 0
    const defer = deferPromise()
    setTimeout(() => {
      defer.resolve(999)
    }, 1e3)
    return defer.promise
  }
  getData2() {
    this.b = 0
    const defer = deferPromise()
    setTimeout(() => {
      defer.resolve({
        a: 1,
        b: 2
      })
    }, 1e3)
    return defer.promise
  }
}
